package net.lcheng.utils;

import com.alibaba.fastjson.JSON;
import net.lcheng.model.OOrderRefund;
import net.lcheng.vo.OrderProductsEntity;
import net.lcheng.vo.OrderRefundModel;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by LV on 2016/7/6.
 */
public class OorderRefund2OrderRefundModel {
    private static OorderRefund2OrderRefundModel ourInstance = new OorderRefund2OrderRefundModel();

    private OorderRefund2OrderRefundModel() {
    }

    private List<OrderRefundModel> getOrderRefundModelList(List<OOrderRefund> list){
        if (list!=null&&list.size()>0) {
            List<OrderRefundModel> orderRefundModels = new ArrayList<>();
//
            for (int i = 0; i < list.size(); i++) {
                OrderRefundModel orderRefundModel = new OrderRefundModel();
                orderRefundModel.setoOrderRefund(list.get(i));
                //将json串类型的orderItems转换成OrderProductsEntity对象
                List<OrderProductsEntity> entities = JSON.parseArray(list.get(i).getOrderProducts(), OrderProductsEntity.class);
                orderRefundModel.setOrderProductsEntityList(entities);
                orderRefundModels.add(orderRefundModel);
            }
            return orderRefundModels;
        }
        return null;
    }

    private OrderRefundModel getOrderRefundModel(OOrderRefund oOrderRefund){
        if (oOrderRefund!=null) {
            OrderRefundModel orderRefundModel = new OrderRefundModel();
            orderRefundModel.setoOrderRefund(oOrderRefund);
            //将json串类型的orderItems转换成OrderProductsEntity对象
            List<OrderProductsEntity> entities = JSON.parseArray(oOrderRefund.getOrderProducts(), OrderProductsEntity.class);
            orderRefundModel.setOrderProductsEntityList(entities);
            return orderRefundModel;
        }
        return null;
    }

    //将List<OOrder>转换成List<OrderModel>
    public static List<OrderRefundModel> getOorderRefund2OrderRefundModel(List<OOrderRefund> list){
        return ourInstance.getOrderRefundModelList(list);
    }

    //将OOrder转换成OrderModel
    public static OrderRefundModel getOorderRefund2OrderRefundModel(OOrderRefund oOrderRefund){return ourInstance.getOrderRefundModel(oOrderRefund);}
}
